//订单确认页面
var basePage = require('../../../common/BasePage');
Page({
    behaviors: [basePage],
    data: {
        logisticsList:[],
		logistics:[],
		selectIndex:0,
		showpicker:false,
		type:"请选择物流方式",
		phone:"请选择物流电话",
		tel:"",
		city1:"",
		city2:"",
		city3:"",
		company:"",
		order_id:[],
		orderInfo:{},
		CompanyIndex:0
    },
    onLoad: function (option) {
		console.log("option",option)
		
		const eventChannel = this.getOpenerEventChannel()
		let that = this;
		eventChannel.on('orderDetail', function (data) {
		  console.log("订单信息", data);
		  that.setData({
			  order_id:data
		  })
		})
        this.getLogistics()
    },
	getLogistics(){
		this.request({
		    url: this.data.host + '/home/index/companyNew',
		    method: 'get'
		},res=>{
		    this.setData({
				logisticsList:res.data,
			})
		});
	},
	clicklog(){
		this.setData({
			showpicker:true
		})
	},
	onCancel(){
		this.setData({
			showpicker:false
		})
	},
	onConfirm(e){
		var index=e.detail.index
		this.setData({
			showpicker:false,
			selectIndex:index,
			type:this.data.logisticsList[index].title,
			tel:"",
			city1:"",
			city2:"",
			city3:"",
			company:"",
			// phone:this.data.logisticsList[index].phone
		})
	},
	clickwuliu(e){
		this.setData({
			selectIndex:e.currentTarget.dataset.index,
			CompanyIndex:0
		})
	},
	clickCompany(e){
		this.setData({
			CompanyIndex:e.currentTarget.dataset.index
		})
		
	},
	onChange(e){
		var key=e.currentTarget.dataset.key
		this.data[key]=e.detail
	},
	//提交
	submit(){
		if(this.data.selectIndex==-1){
			wx.showModal({
			  
			    cancelText: '取消',
			 
			    confirmText: '确认',
			    content: "请选择物流",
			  
			    showCancel: true,
			    title: '提示',
			    success: (result) => {
			      
			    },
			  
			  })
			  return;
		}
		var transfer=""
		if(this.data.city1&&this.data.city2&&this.data.city3){
			transfer=this.data.city1+","+this.data.city2+","+this.data.city3
		}else if(this.data.city1&&this.data.city2){
			transfer=this.data.city1+","+this.data.city2
		}else if(this.data.city1){
			transfer=this.data.city1
		}
		var param={
			order_ids:this.data.order_id,
			company_id:this.data.logisticsList[this.data.selectIndex].company_list[this.data.CompanyIndex].company_id,
			transfer:transfer,
			apll_title:this.data.company,
			apll_phone:this.data.tel
			
		}
		console.log("param",param)
		this.request({
		    url: this.data.host + '/home/order/set_batch_company',
			data:param,
		    method: 'post'
		},res=>{
			wx.showModal({
			  showCancel: false,
			  title: '恭喜',
			  content: "提交成功",
			  success: (result) => {
			    wx.navigateBack({
			      delta: 1,
			    })
			  },
			})
		});
	}
    
})